<script setup>
// This starter template is using Vue 3 <script setup> SFCs
// Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
</script>

<template>
<canvas id="myCanvas" width="360" height="650"></canvas>
</template>

<script>
import facecat from './facecat.js';
let gPaint = new facecat.FCPaint();

/*
 * 重置大小
 */
let resizeAll = function () {
	try {
		const canvas = document.getElementById('myCanvas');
		canvas.width = document.documentElement.clientWidth;
		canvas.height = document.documentElement.clientHeight;
		facecat.scaleCanvas(gPaint);
		facecat.updateViewDefault(gPaint.views);
	} catch (err) {
	}
	facecat.invalidate(gPaint);
};
	
export default { 
	data() {
		return {
		}
	},
	onLoad() {
	}, 
	mounted(){
			const canvas = document.getElementById('myCanvas');
			gPaint.isMobile = facecat.isMobileMode();
			window.addEventListener('resize', resizeAll, true);
			canvas.width = window.innerWidth;
			canvas.height = window.innerHeight;
			gPaint.canvas = canvas;
			facecat.scaleCanvas(gPaint);
			//注册事件
			facecat.addDefaultEvent(canvas, gPaint);
			let canvasSize = new facecat.FCSize((canvas.width / gPaint.ratio / gPaint.scaleFactorX), (canvas.height / gPaint.ratio / gPaint.scaleFactorY));
			//解析加载XML
			let xml = `<?xml version="1.0" encoding="utf-8"?>
			<html xmlns="facecat">
			  <head>
			  </head>
			  <body>
				<div dock="fill" type="tab" selectedindex="0">
				  <div name="TabPage" text="可视化生成" type="tabpage">
					<div name="Div" text="Div" location="15,31" size="312,279">
					  <input type="button" name="Button" text="Button" location="11,22" size="100,20" />
					  <input type="checkbox" name="CheckBox" text="CheckBox" location="11,59" size="100,20" />
					  <label name="Label" text="Label" location="11,92" size="100,20" />
					  <input type="text" name="TextBox" location="11,153" size="100,20" />
					  <table name="Grid" text="Grid" location="125,13" size="169,220">
						<tr>
						  <th name="FCGridColumn" text="FCGridColumn"></th>
						  <th name="FCGridColumn2" text="FCGridColumn2"></th>
						</tr>
						<tr>
						  <td>Cell1</td>
						  <td>Cell2</td>
						</tr>
					  </table>
					</div>
				  </div>
				  <div name="TabPage2" text="代码创建" type="tabpage" />
				</div>
			  </body>
			</html>
			`;
			facecat.renderFaceCat(gPaint, xml);
			//获取第二页
			let tabPage = facecat.findViewByName("TabPage2", gPaint.views);
			let div = new facecat.FCDiv();
			div.location = new facecat.FCPoint(50, 50);
			div.size = new facecat.FCSize(200, 200);
			div.showHScrollBar = true;
			div.showVScrollBar = true;
			div.borderColor = "rgb(150,150,150)";
			facecat.addViewToParent(div, tabPage);
			for (let i = 0; i < 10; i++) {
				let button = new facecat.FCButton();
				button.location = new facecat.FCPoint(i * 40, i * 40);
				button.size = new facecat.FCSize(100, 20);
				button.backColor = "rgb(255,255,255)";
				button.textColor = "rgb(0,0,0)";
				button.borderColor = "rgb(150,150,150)";
				facecat.addViewToParent(button, div);
				button.text = "确定";
			}
			},
			methods: {  
	}
}
</script>
